package com.esri.core.tasks.na;

import com.esri.core.geometry.Point;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.util.d;
import com.esri.core.map.Graphic;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonGenerator;

/* loaded from: classes.dex */
public class NAFeaturesAsFeature implements NAFeatures {
    private boolean compressedRequest;
    private Boolean doNotLocateOnRestrictedElements;
    private boolean hasZ;
    private List<Graphic> mFeatures;
    private SpatialReference spatialRef;
    private String url;

    public NAFeaturesAsFeature() {
        this.mFeatures = new ArrayList();
        this.hasZ = false;
        this.doNotLocateOnRestrictedElements = null;
        this.compressedRequest = false;
        this.url = null;
        this.spatialRef = null;
    }

    public NAFeaturesAsFeature(List<Graphic> list) {
        this.mFeatures = new ArrayList();
        this.hasZ = false;
        this.doNotLocateOnRestrictedElements = null;
        this.compressedRequest = false;
        this.url = null;
        this.spatialRef = null;
        this.mFeatures = list;
    }

    public NAFeaturesAsFeature(List<Graphic> list, boolean z, boolean z2) {
        this.mFeatures = new ArrayList();
        this.hasZ = false;
        this.doNotLocateOnRestrictedElements = null;
        this.compressedRequest = false;
        this.url = null;
        this.spatialRef = null;
        this.mFeatures = list;
        this.hasZ = z;
        this.doNotLocateOnRestrictedElements = Boolean.valueOf(z2);
    }

    public NAFeaturesAsFeature(String str) {
        this.mFeatures = new ArrayList();
        this.hasZ = false;
        this.doNotLocateOnRestrictedElements = null;
        this.compressedRequest = false;
        this.url = null;
        this.spatialRef = null;
        this.url = str;
    }

    public NAFeaturesAsFeature(String str, boolean z, boolean z2) {
        this.mFeatures = new ArrayList();
        this.hasZ = false;
        this.doNotLocateOnRestrictedElements = null;
        this.compressedRequest = false;
        this.url = null;
        this.spatialRef = null;
        this.url = str;
        this.hasZ = z;
        this.doNotLocateOnRestrictedElements = Boolean.valueOf(z2);
    }

    public void addFeature(Graphic graphic) {
        if (graphic == null) {
            return;
        }
        if (this.mFeatures == null) {
            this.mFeatures = new ArrayList();
        }
        this.mFeatures.add(graphic);
    }

    public void addFeature(StopGraphic stopGraphic) {
        addFeature((Graphic) stopGraphic);
    }

    public void addFeatures(Graphic[] graphicArr) {
        if (graphicArr == null) {
            return;
        }
        if (this.mFeatures == null) {
            this.mFeatures = new ArrayList();
        }
        for (Graphic graphic : graphicArr) {
            if (graphic != null) {
                this.mFeatures.add(graphic);
            }
        }
    }

    public void addFeatures(StopGraphic[] stopGraphicArr) {
        addFeatures((Graphic[]) stopGraphicArr);
    }

    public List<Graphic> getFeatures() {
        return this.mFeatures;
    }

    public void setFeatures(Graphic[] graphicArr) {
        List<Graphic> list = this.mFeatures;
        if (list == null) {
            this.mFeatures = new ArrayList();
        } else {
            list.clear();
        }
        addFeatures(graphicArr);
    }

    public void setFeatures(StopGraphic[] stopGraphicArr) {
        setFeatures((Graphic[]) stopGraphicArr);
    }

    public void clearFeatures() {
        List<Graphic> list = this.mFeatures;
        if (list != null) {
            list.clear();
        }
    }

    public SpatialReference getSpatialReference() {
        return this.spatialRef;
    }

    public void setSpatialReference(SpatialReference spatialReference) {
        if (spatialReference != null) {
            this.spatialRef = spatialReference;
        }
    }

    public String getURL() {
        return this.url;
    }

    public void setURL(String str) {
        this.url = str;
    }

    public boolean isHasZ() {
        return this.hasZ;
    }

    public void setHasZ(boolean z) {
        this.hasZ = z;
    }

    public Boolean isDoNotLocateOnRestrictedElements() {
        return this.doNotLocateOnRestrictedElements;
    }

    public void setDoNotLocateOnRestrictedElements(Boolean bool) {
        this.doNotLocateOnRestrictedElements = bool;
    }

    public boolean isCompressedRequest() {
        return this.compressedRequest;
    }

    public void setCompressedRequest(boolean z) {
        this.compressedRequest = z;
    }

    @Override // com.esri.core.tasks.na.NAFeatures
    public String toJson() throws Exception {
        if (this.compressedRequest) {
            StringBuilder sb = new StringBuilder();
            List<Graphic> list = this.mFeatures;
            if (list != null) {
                for (Graphic graphic : list) {
                    Point point = (Point) graphic.getGeometry();
                    sb.append(point.getX());
                    sb.append(",");
                    sb.append(point.getY());
                    if (this.hasZ) {
                        sb.append(",");
                        sb.append(point.getZ());
                    }
                    sb.append(";");
                }
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            return sb.toString();
        }
        StringWriter stringWriter = new StringWriter();
        JsonGenerator a = d.a(stringWriter);
        a.writeStartObject();
        a.writeStringField("type", "features");
        String str = this.url;
        if (str != null && str.length() > 0) {
            a.writeStringField(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, this.url);
        } else {
            a.writeStringField("hasZ", Boolean.toString(this.hasZ));
            List<Graphic> list2 = this.mFeatures;
            if (list2 != null && list2.size() > 0) {
                a.writeArrayFieldStart("features");
                for (Graphic graphic2 : this.mFeatures) {
                    a.writeRawValue(d.a(graphic2, this.spatialRef));
                }
                a.writeEndArray();
            } else {
                throw new IllegalArgumentException("Must specify a url or at least one feature");
            }
        }
        Boolean bool = this.doNotLocateOnRestrictedElements;
        if (bool != null) {
            a.writeStringField("doNotLocateOnRestrictedElements", bool.toString());
        }
        a.writeEndObject();
        a.close();
        return stringWriter.toString();
    }

    public int hashCode() {
        int i = ((((this.doNotLocateOnRestrictedElements.booleanValue() ? 1231 : 1237) + 31) * 31) + (this.hasZ ? 1231 : 1237)) * 31;
        List<Graphic> list = this.mFeatures;
        int hashCode = (i + (list == null ? 0 : list.hashCode())) * 31;
        SpatialReference spatialReference = this.spatialRef;
        int hashCode2 = (hashCode + (spatialReference == null ? 0 : spatialReference.hashCode())) * 31;
        String str = this.url;
        return hashCode2 + (str != null ? str.hashCode() : 0);
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj != null && getClass() == obj.getClass()) {
            NAFeaturesAsFeature nAFeaturesAsFeature = (NAFeaturesAsFeature) obj;
            if (this.doNotLocateOnRestrictedElements == nAFeaturesAsFeature.doNotLocateOnRestrictedElements && this.hasZ == nAFeaturesAsFeature.hasZ) {
                List<Graphic> list = this.mFeatures;
                if (list == null) {
                    if (nAFeaturesAsFeature.mFeatures != null) {
                        return false;
                    }
                } else if (!list.equals(nAFeaturesAsFeature.mFeatures)) {
                    return false;
                }
                SpatialReference spatialReference = this.spatialRef;
                if (spatialReference == null) {
                    if (nAFeaturesAsFeature.spatialRef != null) {
                        return false;
                    }
                } else if (!spatialReference.equals(nAFeaturesAsFeature.spatialRef)) {
                    return false;
                }
                String str = this.url;
                if (str == null) {
                    if (nAFeaturesAsFeature.url != null) {
                        return false;
                    }
                } else if (!str.equals(nAFeaturesAsFeature.url)) {
                    return false;
                }
                return true;
            }
            return false;
        }
        return false;
    }
}
